package elm.example.dao;

import elm.example.po.Food;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/*
    classDescription:食物类的Dao接口
*/
@Repository
public interface IFoodDao extends CrudRepository<Food, Integer> {
    Optional<Food> findFoodByFoodName(String name);

    List<Food> findFoodByBusinessId(Integer businessId);

    @Transactional    //使用Modify自定义方法，需要显式开启事务管理
    @Modifying
    @Query("UPDATE Food f SET f.foodPrice = ?1 WHERE f.foodId = ?2")
    void updateFoodPriceById(Float newPrice, Integer foodId);
}
